package com.lennon.oauth.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.lennon.oauth.store.StoreFactory;

@Controller
@RequestMapping(value = "/test")
public class TestDemoController {

	@RequestMapping(value = "/oauthorizeTest")
	public String oauthorizeTest(ModelMap modelMap) throws UnsupportedEncodingException {
		String response_type = "authorization_code";
		String client_id = "lennon";
		String redirect_uri = "http://localhost:8080/test/oauthorizeTestCallback";
		String param = "response_type=" + response_type+"&client_id="+client_id+"&redirect_uri=" + redirect_uri;
		return "redirect:/authorize?"+param;
	}
	
	@RequestMapping(value = "/oauthorizeTestCallback")
	public String oauthorizeTestCallback(ModelMap modelMap, @RequestParam String code) {
		modelMap.put("code", code);
		return "code";
	}
	
	@RequestMapping(value = "/test")
	public String test(ModelMap modelMap, @RequestParam String token) {
		if(!StoreFactory.getTokenStore().isRightToken(token)) {
			// token 校验失败
			// return error
			return "";
		}
		return "";
	}
}
